#include <iostream>
#include <cmath>
using namespace std;
/*
	t+k=i		i-t
	t-k=i		t-i

*/
int main() {
	
	string str;
	cin>>str;
	int nRet=0x3f3f3f3f;
	for(int i=0;i<26;++i){
		int sum=0;
		for(int j=0;j<static_cast<int>(str.size());++j){
			int t=str[j]-'a';
			sum+=min(abs(t-i),26-abs(t-i));
			
		}
		//cout<<sum<<endl;
		nRet=min(sum,nRet);
	}
	cout<<nRet<<endl;
	
	return 0;
}
